clear
set more off

* Figure 1 *
* Map of GTD attacks

set seed 12345
tsset fips year, yearly

* Table 1 (results) & Table 2 (marginal effects) *
* Mixed Effects Logit Marginal Effects Table *
* Model 1
set seed 12345
xtmelogit rwyn l.(c.nwhtprop c.logcountygdppc c.lfpratenat f.dempres c.citi6016 logtotalpop logiurban loglnd south west midwest splag_rw t tsq tcu) || statefips:  
* outreg2 using "C:\Users\sneme\OneDrive\Desktop\New folder\RW Terror Paper\RW Results\060420\Main Results re clustered on county.doc", replace ctitle(Model 1) addstat(Wald Chisq, e(chi2), Log Likelihood, e(ll))
margins, predict(mu fixedonly) vsquish atmeans 
sum logcountygdppc lfpratenat dempres citi6016 loglnd if e(sample)==1, d
margins, at(l.logcountygdppc = (6.397281 7.998481)) predict(mu fixedonly) vsquish atmeans
margins, at(l.lfpratenat = (55.3933 60.282803)) predict(mu fixedonly) vsquish atmeans
margins, at(dempres = (0 1)) predict(mu fixedonly) vsquish atmeans
margins, at(l.citi6016 = (43.95796 57.02142)) predict(mu fixedonly) vsquish atmeans
margins, at(l.loglnd = (6.522707 7.3080975)) predict(mu fixedonly) vsquish atmeans

* Model 2
set seed 12345
xtmelogit rwyn preselectyr l.(c.polcondist c.nwhtprop c.logcountygdppc c.lfpratenat f.dempres c.citi6016 logtotalpop logiurban loglnd south west midwest splag_rw t tsq tcu) || statefips:  
* outreg2 using "C:\Users\sneme\OneDrive\Desktop\New folder\RW Terror Paper\RW Results\060420\Main Results re clustered on county.doc", append ctitle(Model 2) addstat(Wald Chisq, e(chi2), Log Likelihood, e(ll))
margins, predict(mu fixedonly) vsquish atmeans
sum polcondist logcountygdppc lfpratenat dempres citi6016 loglnd if e(sample)==1, d
margins, at(l.polcondist = (.7964793 .9453434)) predict(mu fixedonly) vsquish atmeans 
margins, at(l.logcountygdppc = (6.416499 8.027444)) predict(mu fixedonly) vsquish atmeans  
margins, at(l.lfpratenat = (55.48838 60.316644)) predict(mu fixedonly) vsquish atmeans  
margins, at(dempres = (0 1)) predict(mu fixedonly) vsquish atmeans  
margins, at(l.citi6016 = (43.77528 56.63952)) predict(mu fixedonly) vsquish atmeans
margins, at(l.loglnd = (6.495482 7.2430217)) predict(mu fixedonly) vsquish atmeans

* Model 3
set seed 12345
xtmelogit rwyn preselectyr l.(c.polcondist c.nwhtprop c.polcondist#c.nwhtprop c.logcountygdppc c.lfpratenat f.dempres c.citi6016 logtotalpop logiurban loglnd south west midwest splag_rw t tsq tcu)|| statefips:
* outreg2 using "C:\Users\sneme\OneDrive\Desktop\New folder\RW Terror Paper\RW Results\060420\Main Results re clustered on county.doc", append ctitle(Model 3) addstat(Wald Chisq, e(chi2), Log Likelihood, e(ll))
margins, predict(mu fixedonly) vsquish atmeans
sum polcondist logcountygdppc lfpratenat dempres citi6016 loglnd if e(sample)==1, d
margins, at(l.polcondist = (.7964793 .9453434)) predict(mu fixedonly) vsquish atmeans 
margins, at(l.logcountygdppc = (6.416499 8.027444)) predict(mu fixedonly) vsquish atmeans  
margins, at(l.lfpratenat = (55.48838 60.316644)) predict(mu fixedonly) vsquish atmeans  
margins, at(dempres = (0 1)) predict(mu fixedonly) vsquish atmeans  
margins, at(l.citi6016 = (43.77528 56.63952)) predict(mu fixedonly) vsquish atmeans
margins, at(l.loglnd = (6.495482 7.2430217)) predict(mu fixedonly) vsquish atmeans

* Model 4
set seed 12345
xtmelogit rwyn preselectyr l.(c.polcondist c.nwhtprop c.logcountygdppc c.logcountygdppc#c.nwhtprop c.lfpratenat f.dempres c.citi6016 logtotalpop logiurban loglnd south west midwest splag_rw t tsq tcu)|| statefips:
* outreg2 using "C:\Users\sneme\OneDrive\Desktop\New folder\RW Terror Paper\RW Results\060420\Main Results re clustered on county.doc", append ctitle(Model 4) addstat(Wald Chisq, e(chi2), Log Likelihood, e(ll))
margins, predict(mu fixedonly) vsquish atmeans
sum polcondist logcountygdppc lfpratenat dempres citi6016 loglnd if e(sample)==1, d
margins, at(l.polcondist = (.7964793 .9453434)) predict(mu fixedonly) vsquish atmeans 
margins, at(l.logcountygdppc = (6.416499 8.027444)) predict(mu fixedonly) vsquish atmeans  
margins, at(l.lfpratenat = (55.48838 60.316644)) predict(mu fixedonly) vsquish atmeans  
margins, at(dempres = (0 1)) predict(mu fixedonly) vsquish atmeans  
margins, at(l.citi6016 = (43.77528 56.63952)) predict(mu fixedonly) vsquish atmeans
margins, at(l.loglnd = (6.495482 7.2430217)) predict(mu fixedonly) vsquish atmeans

* Model 5
set seed 12345
xtmelogit rwyn preselectyr l.(c.polcondist c.nwhtprop c.polcondist#c.nwhtprop c.logcountygdppc c.logcountygdppc#c.nwhtprop c.lfpratenat f.dempres c.citi6016 logtotalpop logiurban loglnd south west midwest splag_rw t tsq tcu)|| statefips:
* outreg2 using "C:\Users\sneme\OneDrive\Desktop\New folder\RW Terror Paper\RW Results\060420\Main Results re clustered on county.doc", append ctitle(Model 5) addstat(Wald Chisq, e(chi2), Log Likelihood, e(ll))
margins, predict(mu fixedonly) vsquish atmeans
sum polcondist logcountygdppc lfpratenat dempres citi6016 loglnd if e(sample)==1, d
margins, at(l.polcondist = (.7964793 .9453434)) predict(mu fixedonly) vsquish atmeans 
margins, at(l.logcountygdppc = (6.416499 8.027444)) predict(mu fixedonly) vsquish atmeans  
margins, at(l.lfpratenat = (55.48838 60.316644)) predict(mu fixedonly) vsquish atmeans  
margins, at(dempres = (0 1)) predict(mu fixedonly) vsquish atmeans  
margins, at(l.citi6016 = (43.77528 56.63952)) predict(mu fixedonly) vsquish atmeans
margins, at(l.loglnd = (6.495482 7.2430217)) predict(mu fixedonly) vsquish atmeans

* Figure 2 *
margins, dydx(l.polcondist) at(l.nwhtprop=(0(5)50)) predict(mu fixedonly) vsquish atmeans 
marginsplot, recast(line) recastci(rarea) yline(0) ylabel(-.0004(.0002).0006) ytitle(Effects on Predicted Mean) xtitle(County Non-White Proportion)
* graph save "C:\Users\sneme\OneDrive\Desktop\New folder\RW Terror Paper\RW Results\060420\Marginal effects polcon Main Results.gph", replace
* graph export "C:\Users\sneme\OneDrive\Desktop\New folder\RW Terror Paper\RW Results\060420\Marginal effects polcon Main Results.png", replace

* Figure 3 *
margins, dydx(l.logcountygdppc) at(l.nwhtprop=(0(5)50)) predict(mu fixedonly) vsquish atmeans 
marginsplot, recast(line) recastci(rarea) yline(0) ylabel(-.0004(.0002).0006) ytitle(Effects on Predicted Mean) xtitle(County Non-White Proportion)
* graph save "C:\Users\sneme\OneDrive\Desktop\New folder\RW Terror Paper\RW Results\060420\Marginal effects gdp Main Results.gph", replace
* graph export "C:\Users\sneme\OneDrive\Desktop\New folder\RW Terror Paper\RW Results\060420\Marginal effects gdp Main Results.png", replace